package service;

import dao.AdminDao;
import dao.AdminDaoImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import pojo.Admin;
import utils.SystemEnum;

import java.util.ArrayList;

public class AdminServiceImpl implements AdminService{
    private AdminDao dao = new AdminDaoImpl();

    @Override
    public ArrayList<Admin> findAll() {
        return dao.findAll();
    }

    @Override
    public Admin findByAdminAcount(Integer account) {
        return dao.findByAdminAcount(account);
    }

    @Override
    public boolean checkAdminPassword(Integer account, String password) {
        Log log = LogFactory.getLog(getClass());
        log.info(SystemEnum.BEGIN);
        boolean tag = false;
        Admin admin = dao.findByAdminAcount(account);
        if(admin!=null){
            if(admin.getPassword().equals(password)){
                log.info(SystemEnum.SUCCESS);
                tag = true;
            }
        }
        if(!tag) log.info(SystemEnum.ERROR_MATCH+"\t"+SystemEnum.ERROR_INEFFECTIVE);
        return tag;
    }

    @Override
    public boolean isSuperAdmin(Integer account) {
        return dao.findByAdminAcount(account).isSuper();
    }

    @Override
    public int insert(Admin admin) {
        return dao.insert(admin);
    }

    @Override
    public int update(Admin admin) {
        return dao.update(admin);
    }

    @Override
    public int delete(Integer account) {
        return dao.delete(account);
    }

    @Override
    public boolean updatePermissions(Integer account) {
        return dao.updatePermissions(account);
    }
}
